package cryptohelp

import (
	"encoding/base64"
	"strings"
)

type Base64Helper struct {
}

func (s *Base64Helper) DecodeString(data string) []byte {
	// 清理数据
	data = strings.TrimSpace(data)
	// 尝试标准解码
	if decoded, err := base64.StdEncoding.DecodeString(data); err == nil {
		return decoded
	}

	// 尝试不带填充的解码
	if decoded, err := base64.RawStdEncoding.DecodeString(data); err == nil {
		return decoded
	}

	// 尝试URL编码
	if decoded, err := base64.URLEncoding.DecodeString(data); err == nil {
		return decoded
	}

	// 尝试不带填充的URL编码
	if decoded, err := base64.RawURLEncoding.DecodeString(data); err == nil {
		return decoded
	}
	//所有Base64解码尝试都失败，直接转换
	return []byte(data)
}
